new Vue({
    el:"#i_bg",
    data:{
        pageInfo:'',
        img_url:"http://192.168.2.106:8848/images/",
        styleObj:{
            backgroundColor:"#ff4e00",
            border:"none",
            height:"23px",
            width:"23px",
            color:"white"
        },
        no_bgc:{
            height:"22px",
            width:"22px",
        },
        loginName:'',
        createTime:'',
        serialNumber:'',
        isPay:111,
        infoFlag:false,
        infoText:'',
        minute:'',
        seconds:'',
        showFlag:false
    },
    methods:{
        getUserOrderPage(pageNum,pageSize)
        {
            axios.get('/api/order/getUserOrderPage',
                {
                    params:{
                        pageNum,pageSize,
                        loginName:this.loginName,
                        isPay:this.isPay,
                        createTime:this.createTime,
                        serialNumber:this.serialNumber
                    }
                }).then(rs=>{
                    if(rs.data.code===200)
                    {
                        this.pageInfo=rs.data.pageInfo
                    }else{
                        this.pageInfo=null
                    }
                console.log(this.pageInfo)
            })
        },
        opera(sign)
        {
            let pageNum=1
            switch(sign)
            {
                case "pre":
                    pageNum=this.pageInfo.hasPreviousPage?this.pageInfo.prePage:1
                    break;
                case "next":
                    pageNum=this.pageInfo.hasNextPage?this.pageInfo.nextPage:this.pageInfo.pages
                    break;
                case "last":
                    pageNum=this.pageInfo.pages
                    break;
            }
            this.getUserOrderPage(pageNum,2)
        },
        //支付方法
        orderPay(id)
        {
            axios.get("/api/alipay/payment",{
                params:{
                    id
                }
            }).then(rs=>{
                console.log(rs.data)
                const box=document.createElement("div")
                box.innerHTML=rs.data
                document.body.appendChild(box)
                console.log(document.body)
                document.forms[1].submit()
            })
        },
        //取消交易
        cancelTrade(id,opera)
        {
            if(confirm("确认取消交易吗"))
            {
                axios.get("/api/order/updateOrderPayment",{
                    params:{
                        id,
                        opera
                    }
                }).then(rs=>{
                    if(rs.data.status==="success")
                    {
                        this.infoText="取消交易成功"
                        this.infoFlag=true
                        setTimeout(()=>{
                            window.location="/api/Member_order.html"
                        },500)
                    }else{
                        this.infoText="取消交易出错了"
                        this.infoFlag=true
                    }
                })
            }

        },
        //删除订单
        delOrder(id,opera)
        {
            if(confirm("确认删除订单吗"))
            {
                axios.get("/api/order/updateOrderPayment",{
                    params:{
                        id,
                        opera
                    }
                }).then(rs=>{
                    if(rs.data.status==="success")
                    {
                        this.infoText="删除成功"
                        this.infoFlag=true
                        setTimeout(()=>{
                            window.location="/api/Member_order.html"
                        },500)
                    }else{
                        this.infoText="删除出错了"
                        this.infoFlag=true
                    }
                })
            }
        },
        backment(serialNumber,cost)
        {
            if(confirm("确认退款吗"))
            {
                axios.get("/api/alipay/backFor",{
                    params:{
                        serialNumber,
                        cost
                    }
                }).then(rs=>{
                    if(rs.data.status==="success")
                    {
                        this.infoText="退款成功"
                        this.infoFlag=true
                        setTimeout(()=>{
                            window.location="/api/Member_order.html"
                        },500)
                    }else{
                        this.infoText="退款出错了"
                        this.infoFlag=true
                    }

                })
            }

        },
        //倒计时
        getTime()
        {
            this.minute=parseInt(window.localStorage.getItem("minute"))
            this.seconds=parseInt(window.localStorage.getItem("seconds"))
            this.showFlag=true
            let n=setInterval(()=>{
                this.seconds--
                if(this.minute==0 && this.seconds==0)
                {
                    this.showFlag=false
                    this.getUserOrderPage(1,2)
                    clearInterval(n)
                }
                if(this.seconds==0)
                {
                    this.minute--
                    this.seconds=59
                }

            },1000)
        },
        closeInfo()
        {
            this.infoFlag=false
        },
    },
    created()
    {
        this.loginName=window.sessionStorage.getItem("loginName")
        this.getUserOrderPage(1,2)
        // this.getTime()
    }
})